<?php
/**
 * 生产订单
 *
 */
class c_shengchandingdan extends base_c
{
    public function __construct($inPath)
    {
        parent::__construct();
        if (self::isLogin() === false) {
            $this->ShowMsg("请先登录！", $this->createUrl("/main/index"));
        }
        if (self::checkRights($inPath) === false) {
            //$this->ShowMsg("您无权操作！",$this->createUrl("/system/index"));
        }
        $this->params['inpath'] = $inPath;
        $this->params['head_title'] = "生产订单-" . $this->params['head_title'];
    }
    public function pageindex($inPath)
    {
        $url = $this->getUrlParams($inPath);
        $shengchandingdanObj = new m_shengchandingdan();
        $this->params['items'] = $shengchandingdanObj->select()->items;
        return $this->render('shengchandingdan/index.html', $this->params);
    }

    public function pageadd($inPath)
    {
        $url = $this->getUrlParams($inPath);
        $gid = (int) $url['gid'] > 0 ? (int) $url['gid'] : (int) $_POST['gid'];
        $goodsObj = new m_goods($gid);

        if (!$_POST) {
            if ($gid) {
                $this->params['goods'] = $goodsObj->get();
            }
            return $this->render('shengchandingdan/add.html', $this->params);
        } else {
            $item = array();
            $item['kuanhao'] = base_Utils::shtmlspecialchars($_POST['kuanhao']);
            if (!$item['kuanhao']) {
                $this->ShowMsg('款号不能够为空！');
            }
            $item['goods_sn'] = base_Utils::shtmlspecialchars($_POST['goods_sn']);
            if (!$item['goods_sn']) {
                $this->ShowMsg('条码不能够为空！');
            }
            $item['goods_name'] = base_Utils::shtmlspecialchars($_POST['goods_name']);
            if (!$item['goods_name']) {
                $this->ShowMsg('商品名称不能够为空！');
            }
            $item['num'] = base_Utils::shtmlspecialchars($_POST['num']);
            if (!$item['num']) {
                $this->ShowMsg('订单数量不能够为空！');
            }
            $item['price'] = base_Utils::shtmlspecialchars($_POST['price']);
            if (!$item['price']) {
                $this->ShowMsg('单件订货金额不能够为空！');
            }

            $shengchandingdanObj = new m_shengchandingdan();
            if ($id) {
                $item['id'] = $id;
            }
            $rs = $shengchandingdanObj->create($item);
            if ($rs) {
                $this->ShowMsg('添加成功', $this->createUrl('/shengchandingdan/index'));
            } else {
                $this->ShowMsg('添加失败，请重试！错误原因：' . $shengchandingdanObj->getError());
            }
        }
    }
}
